﻿namespace Proxima
{
    internal class SynonymDictionary<TKey, TValue> : Dictionary<TKey, TValue>
        where TKey : notnull
    {
        private const string c_containsKeyException = "An item with the same key has already been added. Key: ";
        private readonly Dictionary<TKey, TKey> _synonyms = [];

        public void AddSynonym(TKey synonym, TKey key)
        {
            if (ContainsKey(synonym))
                throw new ArgumentException(c_containsKeyException + synonym.ToString(), nameof(synonym));

            _synonyms.Add(synonym, key);
        }

        public bool TryAddSynonym(TKey synonym, TKey key)
        {
            var result = true;

            if (ContainsKey(synonym) || _synonyms.ContainsKey(synonym))
                result = false;

            _synonyms.Add(synonym, key);

            return result;
        }

        #region Dictionary<TKey, TValue>

        //public new TValue this[TKey key]
        //{
        //    get
        //    {

        //    }
        //    set
        //    {

        //    }
        //}

        public new void Add(TKey key, TValue value)
        {
            if (_synonyms.ContainsKey(key))
                throw new ArgumentException(c_containsKeyException + key.ToString(), nameof(key));

            Add(key, value);
        }

        #endregion Dictionary<TKey, TValue>
    }
}
